﻿Imports System.Data.SqlClient
Public Class en_members_supplyManagement
    Inherits System.Web.UI.Page
    Private sSQL As String
    Private objrd As SqlDataReader = Nothing
    Private objfind As New GetData
    Private ps As New PreparedStatement(sSQL)
    Private i As Integer
    Private pages As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Session("uid") <> Nothing And Session("uid") <> "") Then
            Dim memberId, strErr As String
            Dim companyId As String = ""
            Dim sum, sumdesc As Integer
            i = Request("page")
            If i = Nothing Or i = 0 Then
                i = 1
            End If
            memberId = Session("uid")
            strErr = ""
            ps.strSql = "select * from merchant where owner_id =@ownerId"
            ps.addParameter("ownerId", memberId)
            Dim conn As SqlConnection = objfind.getConn()
            objrd = objfind.dr(ps, strErr, conn, objrd)
            If (objrd.Read()) Then
                companyId = objrd.Item("company_id")
            End If
            ps.strSql = "select count(*) from product_info where active='true' and company_id=@companyId and lang_flag='en' and recommendation <> 'true'"
            ps.parameters.Clear()
            ps.addParameter("companyId", companyId)
            objrd = objfind.dr(ps, strErr, conn, objrd)
            objrd.Read()
            sum = objrd.Item(0)
            pages = (sum \ 10) + 1
            If i >= pages Then
                i = pages
            ElseIf i <= 0 Then
                i = 1
            End If
            If (i = pages) Then
                sumdesc = sum
            Else
                sumdesc = i * 10
            End If
            totalPage.InnerText = i.ToString & "/" & pages.ToString()
            ps.strSql = "select top(" & i & "*10) * from product_info where active='true' and company_id=@companyId and lang_flag='en' and recommendation <> 'true'" & _
                    "and product_id not in (" & _
                    "select top (" & i - 1 & "*10) product_id from product_info where active='true' and company_id=@companyId and lang_flag='en' and recommendation <> 'true' " & _
                    "order by product_name" & _
                    ") and product_id not in (select top(" & sum - sumdesc & ") product_id from product_info where active='true' and company_id=@companyId and lang_flag='en' and recommendation <> 'true'" & _
                    "order by product_name desc) order by product_name"
            ps.parameters.Clear()
            ps.addParameter("companyId", companyId)
            objrd = objfind.dr(ps, strErr, conn, objrd)
            productList.InnerHtml = "<table width=""98%"" border=""0"" cellpadding=""0"" cellspacing=""1"" style=""margin-top:10px;"">" & _
                                         "<tr>" & _
                                            "<td width=""10%"" bgcolor=""#CCCCCC""><input type=""checkbox""/>select</td>" & _
                                            "<td width=""35%"" bgcolor=""#CCCCCC"">product name</td>" & _
                                            "<td width=""15%"" bgcolor=""#CCCCCC"">status</td>" & _
                                            "<td width=""40"" bgcolor=""#CCCCCC"">option</td>" & _
                                         "</tr>"
            While (objrd.Read())
                productList.InnerHtml += "<tr>" & _
                                            "<td bgcolor=""#F5F5F5""> <input type=""checkbox""/></td>" & _
                                            "<td bgcolor=""#F5F5F5""> " & objrd("product_name") & "</td>" & _
                                            "<td bgcolor=""#F5F5F5""> " & objrd("active") & "</td>" & _
                                            "<td bgcolor=""#F5F5F5""> <a href=""members-productedit.aspx?editType=delete&productId=" & objrd("product_id") & """ >delete</a>&nbsp&nbsp&nbsp&nbsp<a href=""members-productupdate.aspx?productId=" & objrd("product_id") & """>edit</a>&nbsp&nbsp&nbsp&nbsp<a href=""members-productedit.aspx?editType=recommend&productId=" & objrd("product_id") & """>recommend</a>" & _
                                         "</tr>"
            End While
            productList.InnerHtml += "</table>"
            pageNav.InnerHtml = "<a href=""members-supplyManagement.aspx?page=1"">home &nbsp;</a>" & _
                                "<a href=""members-supplyManagement.aspx?page=" & i - 1 & """>previous page &nbsp;</a>" & _
                                "<a href=""members-supplyManagement.aspx?page=" & i + 1 & """>next page &nbsp;</a>" & _
                                "<a href=""members-supplyManagement.aspx?page=" & pages & """>end &nbsp;</a>"
            objfind.closeConn(conn)
        Else
            Response.Redirect("../login.aspx")
        End If
    End Sub

    Protected Sub submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles submit.Click
        Response.Redirect("members-supplyManagement.aspx?page=" & page1.Text & "")
    End Sub

End Class